package com.tanhua.admin.mapper;

/**
 * @Author: cl
 * @Date: 2022/5/17 - 05 - 17
 * @Description:
 */

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 日志表
 */
public interface LogMapper extends BaseMapper<Log> {

    /**
     * 根据操作时间和类型统计日志统计用户数量
     *
     * @param type
     * @param logTime
     * @return
     */
    @Select("select count(distinct user_id) from tb_log where type = #{type} and log_time = #{logTime}")
    Integer getByTypeAndLogTime(@Param("type") String type, @Param("logTime") String logTime);


    /**
     * 根据时间统计活跃用户数量
     *
     * @param logTime
     * @return
     */
    @Select("select count(distinct user_id) from  tb_log where log_time = #{logTime}")
    Integer getByLogTime(String logTime);


    /**
     * 查询次日留存 , 从昨天注册的用户中查询今日活跃用户
     *
     * @param today
     * @param yesterday
     * @return
     */
    @Select("select count(distinct user_id) from  tb_log where log_time = #{today} and " +
            "user_id in (SELECT user_id FROM tb_log WHERE TYPE='0102' AND log_time=#{yesterday})")
    Integer getNumRetention1d(@Param("today") String today, @Param("yesterday") String yesterday);
}
